package com.system.controller;

import com.common.annotation.MyLog;
import com.common.controller.BaseController;
import com.system.entity.RotationChart;
import com.system.service.RotationChartService;
import com.system.vo.request.RotationChartDeleteReqVO;
import com.system.vo.request.RotationChartPageReqVo;
import com.system.vo.request.RotationChartReqAddVO;
import com.system.vo.request.RotationChartUpdateReqVO;
import com.system.vo.response.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import javax.validation.Valid;
import java.util.List;
import com.common.res.DataResult;


import javax.validation.Valid;
import java.util.List;

/**
* @author XueHeng
* @since 2020-09-17
*/
@RestController
@RequestMapping("api")
@Api(tags = "页面管理")
public class RotationChartController extends BaseController {

    @Autowired
    private RotationChartService rotationChartService;

    @PostMapping("/rotations")
    @ApiOperation("轮播图列表")
    @MyLog(title = "页面管理",action = "获取轮播图列表")
    @RequiresPermissions("sys:rotationChart:list")
    public DataResult<PageVO<RotationChart>> getAllRotationChart(@RequestBody @Valid RotationChartPageReqVo vo){
        DataResult result =DataResult.success();
        result.setData(this.rotationChartService.getRotationCharts(vo));
        return result;
    }

    @PostMapping("/rotation")
    @RequiresPermissions("sys:rotationChart:add")
    @ApiOperation("新增")
    @MyLog(title = "页面管理",action = "新增轮播图")
    public DataResult add(@Valid @RequestBody RotationChartReqAddVO vo,HttpServletRequest request) {
        DataResult result =DataResult.success();
        String userId = getUserId(request);
        this.rotationChartService.add(vo,userId);
        return result;
    }

    @PutMapping("/rotation")
    @RequiresPermissions("sys:rotationChart:update")
    @ApiOperation("更新")
    @MyLog(title = "页面管理",action = "更新轮播图")
    public DataResult update(@Valid @RequestBody RotationChartUpdateReqVO vo, HttpServletRequest request) {
        DataResult result =DataResult.success();
        String userId = getUserId(request);
        this.rotationChartService.update(vo,userId);
        return result;
    }


    @DeleteMapping(value = "/rotation")
    @RequiresPermissions("sys:rotationChart:delete")
    @ApiOperation("删除")
    @MyLog(title = "页面管理",action = "删除轮播图")
    public DataResult remove(@RequestBody @Valid List<RotationChartDeleteReqVO> vo) {
        DataResult result =DataResult.success();
        this.rotationChartService.delete(vo);
        return result;
    }

    @GetMapping("/rotations")
    @ApiOperation(value = "页面展示")
    @MyLog(title = "页面管理",action = "页面展示")
    public DataResult <List<RotationChart>> getRotationCharts(){
        DataResult result = DataResult.success();
        result.setData(this.rotationChartService.getRotationCharts());
        return result;
    }
}
